import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { NiuSmsService } from '../../services/admin/niu-sms.service';

/**
 * NiuSmsController
 * 对应 PHP: NiuSms Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('notice')
@Controller('adminapi/notice')
export class NiuSmsController {
  constructor(private readonly niuSmsService: NiuSmsService) {}

  /**
   * 牛云短信管理
   * 路由: PUT enable
   * PHP路由: Route::put('enable', 'notice.NiuSms/enable')
   */
  @Put('enable')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async enable(@Body() data: EnableDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: enable

      return await this.niuSmsService.enableNiuSms(params['is_enable']);
    } catch (error) {
      throw new BusinessException('enable操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: GET config
   * PHP路由: Route::get('config', 'notice.NiuSms/getConfig')
   */
  @Get('config')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async getConfig(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getConfig

      return await this.niuSmsService.getConfig();
    } catch (error) {
      throw new BusinessException('getConfig操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: GET packages
   * PHP路由: Route::get('packages', 'notice.NiuSms/getSmsPackageList')
   */
  @Get('packages')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async getSmsPackageList(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getSmsPackageList

      return await this.niuSmsService.packageList(params);
    } catch (error) {
      throw new BusinessException('getSmsPackageList操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: POST send
   * PHP路由: Route::post('send', 'notice.NiuSms/sendMobileCode')
   */
  @Post('send')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async sendMobileCode(@Body() data: SendMobileCodeDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: sendMobileCode

      return await this.niuSmsService.sendMobileCode(params);
    } catch (error) {
      throw new BusinessException('sendMobileCode操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: GET captcha
   * PHP路由: Route::get('captcha', 'notice.NiuSms/captcha')
   */
  @Get('captcha')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async captcha(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: captcha

      return await this.niuSmsService.captcha();
    } catch (error) {
      throw new BusinessException('captcha操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: POST register
   * PHP路由: Route::post('register', 'notice.NiuSms/registerAccount')
   */
  @Post('register')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async registerAccount(
    @Body() data: RegisterAccountDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: registerAccount

      return await this.niuSmsService.registerAccount(data);
    } catch (error) {
      throw new BusinessException('registerAccount操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: POST login
   * PHP路由: Route::post('login', 'notice.NiuSms/loginAccount')
   */
  @Post('login')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async loginAccount(@Body() data: LoginAccountDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: loginAccount

      return await this.niuSmsService.loginAccount(params);
    } catch (error) {
      throw new BusinessException('loginAccount操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: GET send_list/:username
   * PHP路由: Route::get('send_list/:username', 'notice.NiuSms/accountSendList')
   */
  @Get('send_list/:username')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async accountSendList(
    @Param('username') username: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: accountSendList

      return await this.niuSmsService.accountSendList(username, params);
    } catch (error) {
      throw new BusinessException('accountSendList操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: GET info/:username
   * PHP路由: Route::get('info/:username', 'notice.NiuSms/accountInfo')
   */
  @Get('info/:username')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async accountInfo(@Param('username') username: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: accountInfo

      return await this.niuSmsService.accountInfo(username);
    } catch (error) {
      throw new BusinessException('accountInfo操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: POST edit/:username
   * PHP路由: Route::post('edit/:username', 'notice.NiuSms/editAccount')
   */
  @Post('edit/:username')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async editAccount(
    @Param('username') username: string,
    @Body() data: EditAccountDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: editAccount

      return await this.niuSmsService.editAccount(username, params);
    } catch (error) {
      throw new BusinessException('editAccount操作失败', error);
    }
  }

  /**
   * 牛云短信管理
   * 路由: POST reset/password/:username
   * PHP路由: Route::post('reset/password/:username', 'notice.NiuSms/resetPassword')
   */
  @Post('reset/password/:username')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '牛云短信管理' })
  async resetPassword(
    @Param('username') username: string,
    @Body() data: ResetPasswordDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: resetPassword

      return await this.niuSmsService.resetPassword(username, params);
    } catch (error) {
      throw new BusinessException('resetPassword操作失败', error);
    }
  }
}
